package com.RecipeBook.common;

import java.util.ArrayList;

import com.RecipeBook.browse.Browse;
import com.RecipeBook.cooking.CookingMain;
import com.RecipeBook.favourites.Favourites;
import com.RecipeBook.search.Search;
import com.RecipeBook.main.R;
import com.RecipeBook.search.SearchResults;
import com.RecipeBook.shopping.ShoppingList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

/**
 * A specific class that extends Activity, used for all activities such that
 * any activity will be able to access the same Options Menu.
 */
public class RecipeActivity extends Activity {
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.mainmenu, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		finish();
	    // Handle item selection
	    switch (item.getItemId()) {
		    case R.layout.browse:
		    	Intent intentB = new Intent(this, Browse.class);
				startActivity(intentB);
		        return true;
		        
		    case R.layout.cooking:
		    	Intent intentC = new Intent(this, CookingMain.class);
				startActivity(intentC);
		        return true;
		    
		    case R.layout.favourites:
		    	Intent intentF = new Intent(this, Favourites.class);
				startActivity(intentF);
		        return true;
		        
		    case R.layout.search:
		    	Intent intentS = new Intent(this, Search.class);
				startActivity(intentS);
		        return true;
		    case R.layout.shopping:
		    	Intent intentI = new Intent(this, ShoppingList.class);
		    	startActivity(intentI);
		    	return true;
		    default:
		        return super.onOptionsItemSelected(item);
		    }
	}
	
	public void viewSearchResults(ArrayList<Integer> recipeList)
	{
		Intent intentSR = new Intent(this, SearchResults.class);
		intentSR.putIntegerArrayListExtra("rec", recipeList);
		startActivity(intentSR);
	}
	
	public ProgressDialog startProgress()
	{
		ProgressDialog progressDialog;
		progressDialog = new ProgressDialog(RecipeActivity.this);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		progressDialog.setMessage("Creating db...");
		progressDialog.setMax(21828);
		progressDialog.setCancelable(false);
		progressDialog.show();
		return progressDialog;
	}
}
